<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>企业信息</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">
    <link href="../js/plugins/layui/css/layui.css" rel="stylesheet">
</head>
<body>
<div class="wrapper wrapper-content animated fadeIn">
    <div class="row">
        <div class="col-xs-4 text-left">
            <button type="button" class="btn btn-outline btn-primary" id="addCompany">
                <i class="fa fa-plus" aria-hidden="true"> 新增</i>
            </button>
        </div>
        <div class="col-xs-8 form-inline text-right">
            <input type="text" class="form-control" name="search"
                   autocomplete="off" placeholder="请输入关键字" id="companyName" style="width: 200px;display: inline-block">
            <button type="submit" class="btn btn-outline btn-primary searchBtn" data-type="reload">搜索</button>
            <button type="button" class="btn btn-primary" onclick="selectCompany()">确定</button>
        </div>
    </div>
    <table class="layui-hide" id="table_user"></table>
</div>
<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/plugins/layui/layui.all.js"></script>
<script src="../js/loading.js"></script>
<!-- Page-Level Scripts -->
<script>
    $(document).ready(function () {
        $("#addCompany").click(function () {
            layer.open({
                type: 1,
                title: "新增公司",
                area: ['80%', '50%'],
                content: '<div style="padding: 20px">\n' +
                '                        <input type="text" name="number" lay-verify="required|number" autocomplete="off"\n' +
                '                               class="layui-input" value="" placeholder="请输入公司全称">\n' +
                '                </div><div class="layui-form-item"><div class="text-center"><button class="layui-btn" onclick="searchCompany()">确定</button></div></div>'
            });
        });
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            lay('.test-item').each(function () {
                laydate.render({
                    elem: this
                    , trigger: 'click'
                });
            });
        });

        layui.use('table', function () {
            var table = layui.table;
            //方法级渲染
            table.render({
                elem: '#table_user'
                , url: '../data/company_data.json'
                , cellMinWidth: 80
                , cols: [[
                    {checkbox: true, fixed: true}
                    , {field: 'companyName', title: '企业名称', sort: true}
                    , {field: 'legalPerson', title: '法人', sort: true}
                    , {field: 'street', title: '所属街道', sort: true}
                ]]
                , id: 'testReload'
                , page: true
            });

            var $ = layui.$, active = {
                reload: function () {
                    var demoReload = $('#demoReload');

                    //执行重载
                    table.reload('testReload', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            key: {
                                id: demoReload.val()
                            }
                        }
                    });
                }
            };

            $('.searchBtn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    });

    function searchCompany() {
        loading({
            isShow: true,
            text: "正在操作..."
        });
        window.setTimeout(function () {
            loading({
                isShow: false
            });
        }, 500);
        window.setTimeout(function () {
            layer.closeAll();
        }, 800);
        window.setTimeout(function () {
            layer.msg('添加成功，请重新搜索！');
            $("#companyName").val("湖南雄墩控股集团有限公司");
        }, 800);
    };
    function selectCompany() {
            parent.layer.closeAll();
            parent.$("#comName").val("湖南雄墩控股集团有限公司");
    };
</script>
</body>
</html>
